'''
Created on Nov 26, 2010

@author: behrooz
'''
from amscms.bitly_api import bitly_api
from amscms import settings

def shorten_url(url):
    bitly = bitly_api.Connection(settings.BITLY_LOGIN, settings.BITLY_APIKEY)
    data = bitly.shorten(url)
    if data['hash'] is None:
        return None
    if not data['long_url'] == url:
        return None
    return data['url']
     
    
